package listener;

import java.util.HashMap;
import java.util.Map;

public class EventManager<T extends ListenerEvent> {

	private final static EventManager instance = new EventManager();

	public static EventManager getEventManager() {
		return instance;
	}

	private Map<Integer, T> listenerMap;

	public EventManager() {
		listenerMap = new HashMap<>();
	}

	public void addEvent(int eventId, Class<T> clazz) {
		try {
			listenerMap.put(eventId, clazz.newInstance());
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}

	public void tiggerEvent(int eventId) {
		T listnerEvent = listenerMap.get(eventId);
		listnerEvent.event();
	}
}
